﻿using Engine;
using Game;
using Mekiasm.Common;
using static Mekiasm.MekCraftingRecipe;

namespace Mekiasm
{
    public class ElectricCook : ComplexModelItem
    {
        public static int Index;
        public ElectricCook() : base(new ModelItem[] {
            new ModelItem("Handle2.1.000", "pot"), new ModelItem("Handle2.2", "pot"), new ModelItem("Handle2.3", "pot"),
            new ModelItem("Handle1.3", "pot"), new ModelItem("Handle2.1", "pot"), new ModelItem("Handle1.2", "pot"),
            new ModelItem("SideEast", "pot"), new ModelItem("SideWest", "pot"), new ModelItem("SideNorth", "pot"),
            new ModelItem("SideSouth", "pot"), new ModelItem("Base", "pot") }, "pot","烹饪机")
        {
            
        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            return false;
        }
        public override MekBlock.DeviceType GetDeviceType()
        {
            return MekBlock.DeviceType.Electric;
        }

        public override bool OnInteract(SubsystemBlockBehavior blockBehavior, TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            ComponentElectricCook mcomponent = blockBehavior.Project.FindSubsystem<SubsystemBlockEntities>().GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z).Entity.FindComponent<ComponentElectricCook>(true);
            componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new ElectricFoodMachineWidget(mcomponent, componentMiner);
            return true;
        }
        public override void OnBlockAdded(SubsystemBlockBehavior blockBehavior, int value, int oldValue, int x, int y, int z)
        {
            ILibrary.AddBaseEnergyEntity(DisplayName, x, y, z, null,
                ILibrary.GetRotetedConfig(value, new MachineFaceConfig[] {
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.OUT,MekBlock.DeviceType.Item),
            new MachineFaceConfig(MekBlock.MachineMode.OUT,MekBlock.DeviceType.Item)
            }));//1k eu电量
            ElectricSystem.Add(new ElectricCookElement(x, y, z));
        }
        public override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded)
        {
            ElectricSystem.Add(new ElectricCookElement(x, y, z));
        }
        public override void OnBlockRemoved(SubsystemBlockBehavior blockBehavior, int value, int newValue, int x, int y, int z)
        {
            ILibrary.RemoveBlockEntity(x, y, z);
            ElectricSystem.Remove(new Point3(x, y, z));
        }

    }
}
